package org.crystal.tradecraft.strategy.trademodel;

import org.ta4j.core.BarSeries;
import org.ta4j.core.TradingRecord;
import org.ta4j.core.backtest.TradeExecutionModel;
import org.ta4j.core.num.Num;

public class TradeClosePriceOnNextOpenModel implements TradeExecutionModel {

    @Override
    public void execute(int index, TradingRecord tradingRecord, BarSeries barSeries, Num amount) {
        int indexOfExecutedBar = index + 1;
        if (indexOfExecutedBar <= barSeries.getEndIndex()) {
            tradingRecord.operate(indexOfExecutedBar, barSeries.getBar(indexOfExecutedBar).getClosePrice(), amount);
        }
    }
}
